<?php
class id5_crypt{
	function id5_crypt()
	{
		//加密校验位
		$this->string_in = "phV[s}eUw~RyHQ&,<9?BA=Xf3uM:cJ@g*qTi%l4rCn6]S5Wj>Ib#\$D-mEt.GP{L|a!zYNxFo08;K1O)+dZk(v2^7_";
		$this->string_out = "~!@#$%^&*()_-+={}[]|:;<,>.?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	}
	function Translate($source,$in,$out){
		$s_lenght = strlen($source);
		$result = "";
		for($i=0;$i<$s_lenght;$i++){
			$temp = substr($source,$i,1);
			$num = intval(strpos($in,$temp));
			$temp = substr($out,$num,1);
			$result .= $temp;
		}
		return $result;
	}
	//加密
	function EncryptString($source) 
	{
		//exit($this->string_out);
		$lenght = strlen($this->string_out);
		$offset = rand(0,strlen($source));
		//exit();
		$result = substr($this->string_in,$offset,1);
		$in = $this->string_in.$this->string_in;
		$in = substr($in,$offset,$offset+$lenght);
		$temp = $this->Translate($source,$in,$this->string_out);
		return $result.$temp;
	}
	//解密
	function DecryptString($source)
	{
		$lenght = strlen($this->string_out);
		$offset = strpos($this->string_in,substr($source,0,1));
		$in = $this->string_in.$this->string_in;
		$in = substr($in,$offset,$offset+$lenght);
		$result = $this->Translate(substr($source,1),$this->string_out,$in);
		return $result;
	}
}
/*
$i = new id5_crypt();
$temp = $i->EncryptString("888888");
echo $i->DecryptString($temp);
*/
?>